package thread;

public class Demo13 {
    public static void main(String[] args) throws InterruptedException {
        Thread t2 = new Thread(() -> {
            for (int i = 0; i < 4; i++) {
                System.out.println("t2");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });

        Thread t1 = new Thread(() -> {
            //t1一进来，就先等t2结束
            try {
                //这里加sleep->保证t2已经start
                Thread.sleep(1000);
                t2.join();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            for (int i = 0; i < 3; i++) {
                System.out.println("t1");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });



        t1.start();
        t2.start();

        t1.join();
        t2.join();
        System.out.println("main end");
    }
}
